/*
                  Timer Class Implementation
*/
#include "Timer.h"

Timer::Timer()
{
    iStartTicks = 0;
    iPausedTicks = 0;
    bPaused = false;
    bStarted = false;
}

Timer::~Timer()
{

}

void Timer::Start()
{
    bStarted = true;

    bPaused = false;

    iStartTicks = SDL_GetTicks();
}

void Timer::Stop()
{
    bStarted = false;

    bPaused = false;
}

int Timer::getTicks()
{
    if( bStarted == true )
    {
        if( bPaused == true )
        {
            return iPausedTicks;
        }
        else
        {
            return SDL_GetTicks() - iStartTicks;
        }
    }

    return 0;
}

void Timer::Pause()
{
    if( ( bStarted == true ) && ( bPaused == false ) )
    {
        bPaused = true;

        iPausedTicks = SDL_GetTicks() - iStartTicks;
    }
}

void Timer::Unpause()
{
    if( bPaused == true )
    {
        bPaused = false;

        iStartTicks = SDL_GetTicks() - iPausedTicks;

        iPausedTicks = 0;
    }
}

bool Timer::isStarted()
{
    return bStarted;
}

bool Timer::isPaused()
{
    return bPaused;
}
